package net.xju.service.impl;

import java.time.LocalDateTime;
import net.xju.common.utils.PageInfo;
import net.xju.dao.AnnouncementDao;
import net.xju.entity.Announcement;
import net.xju.service.AnnouncementService;

import java.util.List;

public class AnnouncementServiceImpl implements AnnouncementService {
    AnnouncementDao announcementDao = new AnnouncementDao();

    @Override
    public List<Announcement> list() {
        return announcementDao.list();
    }

    @Override
    public Announcement selectById(int id) {
        return announcementDao.selectById(id);
    }

    @Override
    // 在 AnnouncementServiceImpl.java 中
    public void insert(Announcement announcement) {
        // 如果publishDate为null，则设置为当前时间
        if (announcement.getPublishDate() == null) {
            announcement.setPublishDate(LocalDateTime.now());
        }
        announcementDao.insert(announcement);
    }

    @Override
    public Boolean update(Announcement announcement) {
        return announcementDao.update(announcement);
    }

    @Override
    public boolean deleteById(int id) {
        return announcementDao.deleteById(id);
    }

    @Override
    public PageInfo<Announcement> pageList(String title, Integer pageNo, Integer pageSize) {
        return announcementDao.pageList(title, pageNo, pageSize);
    }
}